package archforce.atp.x.ui.impl.right;

import archforce.atp.x.ui.frame.component.AbstractRowItemComponent;
import archforce.atp.x.ui.impl.common.component.IPPortItemComponent;
import archforce.atp.x.ui.impl.left.IPPortModel;

/**
 * @author wx
 * @version 1.0
 * @date 2022/4/11 11:55
 */
public class IPPortMappingItemComponent extends AbstractRowItemComponent<IPPortMappingModel> {

    private IPPortItemComponent local;
    private IPPortItemComponent remote;

    public IPPortMappingItemComponent() {
        this(new IPPortMappingModel(true));
    }

    public IPPortMappingItemComponent(IPPortMappingModel date) {
        super();
        init(date);
    }

    private void init(IPPortMappingModel date){
        this.local = new IPPortItemComponent();
        this.remote = new IPPortItemComponent();
        this.local.setBindData(new IPPortModel(date.getLocal(), date.getlPort()));
        this.remote.setBindData(new IPPortModel(date.getRemote(), date.getrPort()));
        add(local);
        add(remote);
    }

    @Override
    public void setBindData(IPPortMappingModel bindData) {
        if(bindData == null){
            bindData = new IPPortMappingModel(true);
        }
        this.local.setBindData(new IPPortModel(bindData.getLocal(), bindData.getlPort()));
        this.remote.setBindData(new IPPortModel(bindData.getRemote(), bindData.getrPort()));
    }

    @Override
    public IPPortMappingModel getBindData() {
        IPPortModel lBindData = this.local.getBindData();
        IPPortModel rBindData = this.remote.getBindData();
        return new IPPortMappingModel(lBindData.getIp(),lBindData.getPort(), rBindData.getIp(), rBindData.getPort());
    }
}
